package com.elink.enginerring.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.elink.enginerring.dao.LabelMapper;
import com.elink.enginerring.domain.Label;
import com.elink.enginerring.service.LabelService;

@Service
public class LabelServiceImpl implements LabelService {
	@Autowired
	private LabelMapper labelMapper;

	@Override
	public Object add(String labels,String userId) {

		int maxId = labelMapper.getMaxId();
		int maxSeq = labelMapper.getMaxSeq();
		String tagId = "";
		List<Label> list = new ArrayList<Label>();
		for (String label : labels.split(",")) {
			Label l = new Label();
			l.setLabelId(++maxId);
			l.setUserId(userId);
			l.setLabelName(label);
			l.setSequence(++maxSeq);
            tagId += maxId +",";
            list.add(l);
		}
		labelMapper.insertBatch(list);
		 return tagId.substring(0,tagId.length()-1);
	}
}
